package com.qiandw.security

import javax.servlet.http.{HttpServletRequest, HttpServletResponse}

import org.springframework.security.core.AuthenticationException
import org.springframework.security.web.AuthenticationEntryPoint
import org.springframework.stereotype.Component

@Component
class RestAuthenticationEntryPoint extends AuthenticationEntryPoint {
  override def commence(request: HttpServletRequest, response: HttpServletResponse, authException: AuthenticationException): Unit = {

    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED)
    response.addHeader("WWW-Authenticate", "Basic realm=" + "TEST")
    val writer = response.getWriter
    writer.println("HTTP Status 401 : " + authException.getMessage)

  }



}
